package com.c.ctgproject.wiget.dialog

import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.c.ctgproject.R
import com.c.ctgproject.utils.showToast
import kotlinx.android.synthetic.main.layout_dialog_input.*

/**
 *作者:LiBW
 *创建日期: 2021/7/9
 *描述:输入框Dialog
 */
class InputDialog(private val callback: InPutDialogCallBack) : DialogFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.layout_dialog_input, container, false)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.inputDialog)
    }

    override fun onStart() {
        super.onStart()
        val dm = DisplayMetrics()
        requireActivity().windowManager.defaultDisplay.getMetrics(dm)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mConfirmRL.setOnClickListener {
            val msg = mOpinionET.text.toString()
            if (msg.isEmpty()) {
                requireContext().showToast("请输入审核意见")
            } else {
                callback.dialogResultText(msg)
            }
        }
    }

    interface InPutDialogCallBack {
        fun dialogResultText(msg: String)
    }
}